package xj.model.uml;

import static xj.model.uml.UMLModelConstants.ATTR_TERMINATE;
import static xj.model.uml.UMLModelConstants.ROLE_EXECUTION_OCCURANCE;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class LifeLine extends ExecutionOccurance {

  public LifeLine() {
    this(null, null);
  }

  public LifeLine(String name) {
    this(name, null);
  }

  public LifeLine(UMLObject c) {
    this(null, c);
  }

  public LifeLine(String name, UMLObject c) {
    super(name);
    setUMLObject(c);
  }

  public boolean isTerminate() {
    return terminate;
  }

  public void setTerminate(boolean t) {
    terminate = t;
    setAttribute(ATTR_TERMINATE, terminate);
  }

  @Override
  public List<ExecutionOccurance> getExecutionOccurances() {
    return executions;
  }

  @Override
  public void addExecutionOccurance(ExecutionOccurance e) {
    if (e != null) {
      executions.add(e);
      addOwnedElement(e, ROLE_EXECUTION_OCCURANCE);
    }
  }

  @Override
  public void removeExecutionOccurance(ExecutionOccurance e) {
    if (e != null) {
      executions.remove(e);
      removeOwnedElement(e);
    }
  }

  @Override
  public Object clone() throws CloneNotSupportedException {
    LifeLine l = (LifeLine) super.clone();

    l.executions = new ArrayList<ExecutionOccurance>();
    Iterator<ExecutionOccurance> iter = executions.iterator();
    while (iter.hasNext()) {
      ExecutionOccurance e = iter.next();
      l.addExecutionOccurance((ExecutionOccurance) e.clone());
    }
    return l;
  }

  protected boolean terminate;

  protected List<ExecutionOccurance> executions = new ArrayList<ExecutionOccurance>();

}
